﻿using Microsoft.VisualBasic.Devices;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace SharpDepend.WPF
{
    class EnviromentStatisticsManager : IEnviromentStatisticsManager
    {
        class EnviromentStatisticsClass : IEnviromentStatistics
        {
            private StringBuilder mSB = new StringBuilder();
            private ComputerInfo mComputerInfo = new ComputerInfo();

            public long AppMemoryUsed
            {
                get
                {
                    return GC.GetTotalMemory(false);
                }
            }

            public long TotalMemory
            {
                get
                {
                    return (long)mComputerInfo.TotalPhysicalMemory;
                }
            }

            public int CPUSpeed
            {
                get
                {
                    return -1;
                }
            }

            public int CPUProcessors
            {
                get
                {
                    return Environment.ProcessorCount;
                }
            }

            public string Device
            {
                get
                {
                    return Environment.MachineName;
                }
            }

            public double ScaleFactor
            {
                get
                {
                    var dpiXProperty = typeof(SystemParameters).GetProperty("DpiX", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
                    var dpiYProperty = typeof(SystemParameters).GetProperty("Dpi", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);

                    var dpiX = (int)dpiXProperty.GetValue(null, null);
                    var dpiY = (int)dpiYProperty.GetValue(null, null);

                    return dpiX / 96.0;
                }
            }
        }

        private static EnviromentStatisticsClass mInstance;

        public IEnviromentStatistics EnviromentStatistics
        {
            get
            {
                if (mInstance == null)
                {
                    mInstance = new EnviromentStatisticsClass();
                }

                return mInstance;
            }
        }
    }
}
